﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using DataAccess.SqlClient;
using Model;
using ApiDAL.Common;

namespace Dal
{
        #region 注册
    public class UsertDAL
    {
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="account"></param>
        /// <param name="pwd"></param>
        /// <param name="name"></param>
        /// <param name="addr"></param>
        /// <param name="tel"></param>
        /// <returns></returns>
        public int Regin(string account, string pwd, string name, string addr, string tel)
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "loginf";
            sql.CommandType = CommandType.StoredProcedure;
            SqlParameter cc = new SqlParameter();
            cc.Value = account;
            cc.ParameterName = "@account";
            cc.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc);

            SqlParameter cc1 = new SqlParameter();
            cc1.Value = pwd;
            cc1.ParameterName = "@pwd";
            cc1.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc1);
            SqlParameter cc2 = new SqlParameter();
            cc2.Value = name;
            cc2.ParameterName = "@name";
            cc2.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc2);
            SqlParameter cc3 = new SqlParameter();
            cc3.Value = addr;
            cc3.ParameterName = "@addr";
            cc3.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc3);

            SqlParameter cc4 = new SqlParameter();
            cc4.Value = tel;
            cc4.ParameterName = "@tel";
            cc4.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc4);

            int i = Convert.ToInt32(SqlDataAccess.ExecScalar(sql));
            return i;


        }
       #endregion

        #region 登陆
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="account"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public int login(string account, string pwd)
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "deng";
            sql.CommandType = CommandType.StoredProcedure;
            SqlParameter cc = new SqlParameter();
            cc.Value = account;
            cc.ParameterName = "@name";
            cc.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc);

            SqlParameter cc1 = new SqlParameter();
            cc1.Value = pwd;
            cc1.ParameterName = "@Upwd ";
            cc1.SqlDbType = System.Data.SqlDbType.VarChar;
            sql.Parameters.Add(cc1);


            int i = Convert.ToInt32(SqlDataAccess.ExecScalar(sql));
            return i;
        }
        #endregion

        #region 显示用户
        /// <summary>
        ///显示用户
        /// </summary>
        /// <returns></returns>
        public List<Usert> showuser()
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "select * from Usert";
            DataSet ds = SqlDataAccess.ExecDataset(sql);
            DataTable dt = ds.Tables[0];
            return DataReaderToObjectHelper.DataTableToList<Usert>(dt);
        }
        #endregion

    }
}
